package me.ingxin.android.router.route

import me.ingxin.android.router.base.DataExtras

/**
 * Created by ingxin on 2022/4/18
 * @param resultCode 结果状态码，可以根据业务需求定义，但不可以保留字段重复。
 * 保留字段[Result.SUCCEED]...[Result.NO_RESULT]
 */
class Result(val resultCode: Int = SUCCEED) : DataExtras<Result>() {

    val resultStr: String
        get() = when (resultCode) {
            SUCCEED -> "SUCCEED"
            FAIL -> "FAIL"
            CANCEL -> "CANCEL"
            NO_RESULT -> "NO_RESULT"
            INTERRUPTED -> "INTERRUPTED"
            NOT_FOUND -> "NOT_FOUND"
            NOT_SUPPORTED -> "NOT_SUPPORTED"
            INVALID_ROUTE -> "INVALID_ROUTE"
            else -> resultCode.toString()
        }

    companion object {

        /**操作成功*/
        const val SUCCEED = 0

        /**操作失败*/
        const val FAIL = -61

        /**操作取消*/
        const val CANCEL = -62

        /**
         * 没有调用[RouteHandler.setResult]，或者异步调用[RouteHandler.setResult]但没有启用hold
         * 1.不调用[RouteHandler.setResult]说明忽略返回值，这种情况应该禁用hold功能，否则内存泄漏
         * 2.通过异步方式调用了[RouteHandler.setResult]，但没有启用hold功能，导致异步功能开启失败
         */
        const val NO_RESULT = -63

        /**被拦截器中断*/
        const val INTERRUPTED = -64

        /**找不到路由*/
        const val NOT_FOUND = -65

        /**不支持的类型*/
        const val NOT_SUPPORTED = -66

        /**无效路由*/
        const val INVALID_ROUTE = -67

    }

}